import * as THREE from "three";
import gsap from "gsap";
const sizes = {
  width: 800,
  height: 600,
};

//创建第一个场景
const scene = new THREE.Scene();

//创建物体
//几何体
const geometry = new THREE.BoxGeometry(1, 1, 1);
//材质
const material = new THREE.MeshBasicMaterial({ color: "orange" });
//创建网格
const cube = new THREE.Mesh(geometry, material);
//将网格添加到场景
scene.add(cube);

//创建摄像机
const camera = new THREE.PerspectiveCamera(60, sizes.width / sizes.height);
//相机位置
camera.position.x = 3;
camera.lookAt(cube.position);

// 将相机加入场景
scene.add(camera);

//创建渲染器材
const renderer = new THREE.WebGLRenderer();
renderer.setSize(sizes.width, sizes.height);
document.body.appendChild(renderer.domElement);

// window.requestAnimationFrame

// renderer.render(scene, camera);

// const clock = new THREE.Clock();

// const change = () => {
//   let elapsedTime = clock.getElapsedTime();
//   //   console.log(elapsedTime);

//   cube.rotation.y = elapsedTime;
//   renderer.render(scene, camera);

//   window.requestAnimationFrame(change);
// };

// change();

const change = () => {
  //   gsap.to(cube.position, { duration: 1, delay: 1, x: 2 });
  //   gsap.to(cube.position, { duration: 1, delay: 2, x: 0 });
  renderer.render(scene, camera);

  window.requestAnimationFrame(change);
};

change();
